package com.yunji.framework_template.web.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yunji.framework_template.biz.service.NewsSourcesService;
import com.yunji.framework_template.common.web.Page;
import com.yunji.framework_template.common.web.Result;
import com.yunji.framework_template.orm.persistence.model.NewsSources;

/**
 * Created by fenglibin on 2018/11/26.
 */
@Controller
@RequestMapping("/newsSources/")
public class NewsSourcesController {

    @Autowired
    NewsSourcesService newsSourcesService;

    @RequestMapping("selectAll")
    @ResponseBody
    public Result<List<NewsSources>> selectAll() {
        return Result.success(newsSourcesService.selectAll());
    }

    @RequestMapping("select")
    @ResponseBody
    public Result<NewsSources> selectByPrimaryKey(Integer id) {
        return Result.success(newsSourcesService.selectByPrimaryKey(id));
    }

    @RequestMapping("selectByCondition")
    @ResponseBody
    public Result<List<NewsSources>> selectByCondition(NewsSources record) {
        return Result.success(newsSourcesService.selectByCondition(record));
    }

    @RequestMapping("count")
    @ResponseBody
    public Result<Integer> count(NewsSources record) {
        return Result.success(newsSourcesService.count(record));
    }

    @RequestMapping("insert")
    @ResponseBody
    public Result<Integer> insertSelective(NewsSources record) {
        return Result.success(newsSourcesService.insertSelective(record));
    }

    @RequestMapping("update")
    @ResponseBody
    public Result<Integer> updateByPrimaryKeySelective(NewsSources record) {
        return Result.success(newsSourcesService.updateByPrimaryKeySelective(record));
    }

    @RequestMapping("selectByPage")
    @ResponseBody
    public Result<Page<List<NewsSources>>> selectByPage(Page<NewsSources> page) {
        List<NewsSources> list = null;
        page = page.sequentialDisplayCalculate(newsSourcesService.count(page.getObj()));
        if (page.getTotalCount() > 0) {
            list = newsSourcesService.selectByPage(page);
        }
        Page<List<NewsSources>> result = new Page<List<NewsSources>>(page, list);
        return Result.success(result);
    }

    @RequestMapping("deleteByCondition1")
    @ResponseBody
    public Result<Integer> deleteByCondition(NewsSources record) {
        return Result.success(newsSourcesService.deleteByCondition(record));
    }

    @RequestMapping("delete1")
    @ResponseBody
    public Result<Integer> deleteByPrimaryKey(Integer id) {
        return Result.success(newsSourcesService.deleteByPrimaryKey(id));
    }

}
